package com.lianwei.hospital.controller;

import com.lianwei.hospital.Service.DepartmentService;
import com.lianwei.hospital.Service.Impl.DepartmentInfoImpl;
import com.lianwei.hospital.module.entity.DepartmentInfo;
import com.lianwei.hospital.module.entity.DoctorInfo;
import com.lianwei.hospital.module.vo.DoctorVO;
import com.lianwei.hospital.utils.PageUtil;
import com.lianwei.hospital.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/department")
public class DepartmentInfoController {
    @Autowired
    private DepartmentService departmentService;

    @GetMapping("/selectById")
    public Result<DepartmentInfo> Select(Integer i) throws Exception {
        System.out.println(i+"\n\n");
        DepartmentInfo departmentInfo = departmentService.selectByPrimaryKey(i);
        return Result.buildResult(Result.Status.OK,departmentInfo);
    }

    @PutMapping
    public Result<List<DepartmentInfo>> Insert(@RequestBody DepartmentInfo departmentInfo) throws Exception {
        System.out.println(departmentInfo);
        if(departmentService.insert(departmentInfo)){
            List<DepartmentInfo> departmentInfoList = departmentService.selectAll();
            return Result.buildResult(Result.Status.OK,departmentInfoList);
        }
        return Result.buildResult(Result.Status.BAD_REQUEST);
    }

    @DeleteMapping
    public Result<List<DepartmentInfo>> Delete(@RequestBody DepartmentInfo departmentInfo) throws Exception {
        System.out.println(departmentInfo);
        if(departmentService.deleteByPrimaryKey(departmentInfo.getId())){
            List<DepartmentInfo> departmentInfoList = departmentService.selectAll();
            return Result.buildResult(Result.Status.OK,departmentInfoList);
        }
        return Result.buildResult(Result.Status.BAD_REQUEST);
    }

    @PostMapping
    public Result<List<DepartmentInfo>> Update(@RequestBody DepartmentInfo departmentInfo) throws Exception {
        System.out.println(departmentInfo);
        if(departmentService.updateByPrimaryKey(departmentInfo)){
            List<DepartmentInfo> departmentInfoList = departmentService.selectAll();
            return Result.buildResult(Result.Status.OK,departmentInfoList);
        }
        return Result.buildResult(Result.Status.BAD_REQUEST);
    }

    @GetMapping("/selectAll")
    public Result<List<DepartmentInfo>> abc() throws Exception {
        List<DepartmentInfo> departmentInfoList = departmentService.selectAll();
        return Result.buildResult(Result.Status.OK,departmentInfoList);
    }
}
